package cn.edu.szpt.qqdemov3.fragments;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import java.util.ArrayList;
import java.util.List;

import cn.edu.szpt.qqdemov3.MainActivity;
import cn.edu.szpt.qqdemov3.R;
import cn.edu.szpt.qqdemov3.adapters.QQMessageAdapter;
import cn.edu.szpt.qqdemov3.beans.QQMessageBean;

public class QQMessageFragment extends Fragment {
    private ListView lvMessage;
    private List<QQMessageBean> data;
    private ImageView imgLoginIcon;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=null;
        view = inflater.inflate(R.layout.activity_qqmessage,container,false);
        lvMessage = view.findViewById(R.id.lvMessage);
        imgLoginIcon = view.findViewById(R.id.imgLoginIcon);

        Bitmap bmp = BitmapFactory.decodeFile(MainActivity.loginedUser.getQq_imgurl());
        imgLoginIcon.setImageBitmap(bmp);

        data = new ArrayList<QQMessageBean>();
        initialData();

        QQMessageAdapter adapter = new QQMessageAdapter(getContext(),data);

        lvMessage.setAdapter(adapter);
        return view;
    }

    private void initialData(){
        data.clear();
        String[] names = {"刘备","关羽","张飞","赵云","诸葛亮","黄忠","魏延","曹操","孙权"};
        int[] imgs ={R.drawable.liubei,R.drawable.guanyu,R.drawable.zhangfei,R.drawable.zhaoyun,
                R.drawable.zhugeliang,R.drawable.huangzhong,R.drawable.weiyan,R.drawable.caocao,
                R.drawable.sunquan };
        for(int i=0;i<names.length;i++){
            QQMessageBean bean = new QQMessageBean(names[i],imgs[i],"Hello",
                    "下午 2：15",3);
            data.add(bean);
        }
    }
}
